<div class="panel-body" >

      

  <div class="panel panel-default">

    <div>
   <div class="row">

 <div class="col-sm-12" >
 <div class="panel-heading">


<a href="javascript:void(0);"  onclick="pushToDiversity();"><button class="btn btn-default btn-sm "><i class="fa fa-edit fa-lg"></i>&nbsp; 添加到分集</button></a>
  

<!--隐藏域-->
<input type="hidden" id ="fileOptIds" name="fileOptIds">


</div>
 </div>


 </div>
      <table id="chooseFileTable" class="table table-striped m-b-none">
      </table>
    
    </div>

</div>
                
            </div>




          <script type="text/javascript" >


    function pushToDiversity(){

      

 var fileOptIds = $('#fileOptIds').val();
     if(''==fileOptIds){
    top.layer.msg('请至少选择一项', {icon: 6});
       return false;
    }

    top.layer.confirm('您确定添加这些信息吗', function(index){

    var postInfoUrl = API_URL+"program_diversity";

    var fileOptArrs = fileOptIds.split(',');

    for(var i = 0;i< fileOptArrs.length;i++ ){

         var infoUrl = API_URL+"file_info?query=delflag:0,Id:"+fileOptArrs[i];

          var formData =  MY_ASYNC_AJAX(infoUrl)[0];


          var diversityObj ={
   
    "ProgramId": Number(programIdValue),
    "DiversityId": 2,
    "DiversityUuid": "",
    "DiversityTitle": formData.FileTitle,
    "DiversityIntroduction": "",
    "OriginalFileId": formData.Id,
    "OriginalFileUuid": "",
    "DiversityPlayCount": 0,
    "AdderId": 1,
    "AdderName": "1",
    "AddTime": getNowDBFormatDate(),
    "UpdaterId": 1,
    "UpdaterName": "1",
    "UpdateTime": getNowDBFormatDate(),
    "DelFlag": "0"
  }

         

     $.ajax({
         url : postInfoUrl,
        type : 'post',
         data: JSON.stringify(diversityObj),
       cache : false,
     success : function(data) { 
                  
                  }  
             }); 

        }
         top.layer.msg('添加成功', {icon: 6});
        top.layer.close(index);

dataSet  =  MY_ASYNC_AJAX(diversityDtUrl);

  });
      













    }




function checkFileOne(){
  var fileOptIds = '';
  $("input[name='fileIds']:checkbox:checked").each(function(){ 
      fileOptIds+=$(this).val() +',';
       });
   if(''!=fileOptIds){
        fileOptIds = fileOptIds.substring(0,fileOptIds.length-1);
      }
$('#fileOptIds').val(fileOptIds);

  console.log($('#fileOptIds').val());
}



 var dtUrl = API_URL+"file_info?query=delflag:0";

    $(document).ready(function(){

    $('#chooseFileTable').dataTable({      
        "ajax": {
                "url": dtUrl,
                "dataSrc": ""
            },
        "columns": [
         { data : "Id",
                    title: "<input type='checkbox' id='allFileChecked' name='allFileChecked' />",
                  orderable: false , 
              render : function(data, type, full, meta) {
            return '<input type="checkbox" value="'+ data + '" name="fileIds" onclick="checkFileOne()"/>';
           }},
            { "data": "Id","width":"auto","title":"ID" },
            { "data": "FileTitle" ,"width":"auto","title": "标题"},
            { "data": "FileExtName" ,"width":"auto","title": "扩展名"},
            { "data": "FileSize" ,"width":"auto","title": "文件大小",
                render: function (data, type, row, meta) {
                        return bytesToSize(data);
                    }},
            { "data": "TranscodeStatus" ,"width":"auto","title": "转码状态",
              render : function(data, type, full, meta) {
                  if(data==0){
                          return "<i  title='无需转码' class='label label-info'>无需转码</i>"; 
                      }else if(data==1){
                        return "<i  title='转码完成' class='label label-primary'>转码完成</i>"; 
                      }else if(data==2){
                        return "<i  title='等待转码' class='label label-danger'>等待转码</i>"; 
                      }else if(data==3){
                        return "<i  title='正在转码' class='label label-success'>正在转码</i>"; 
                      }
           }
           },
           
            { "data": "UpdateTime" ,"width":"auto","title": "更新时间",
                    render: function (data, type, row, meta) {

                        return getDateTime(data);
                    }}
        ],


   initComplete:function(data){



//全选、反选
$('#allFileChecked').on('click' , function(){
  var boxes = document.getElementsByName("fileIds");
    for(i=0;i<boxes.length;i++){
                boxes[i].checked = this.checked;
    }
    var fileOptIds ='';
    if(this.checked){
      $("input[name='fileIds']:checkbox:checked").each(function(){ 
      fileOptIds+=$(this).val() +',';
       });
    }else{
  fileOptIds='';
      }
      if(''!=fileOptIds){
        fileOptIds = fileOptIds.substring(0,fileOptIds.length-1);
      }
      $('#fileOptIds').val(fileOptIds);
});

},

         //当处理大数据时，延迟渲染数据，有效提高Datatables处理能力
        deferRender: true,
        processing: true,
        language: {
           url: 'vendor/jquery/datatables/Chinese.json'
    },
    responsive: true,
    searching: true,
    ordering: true,
    lengthChange: true 

});
});  

          </script>
<!--layer弹出层1-->
